package demo2;

public class Person2 implements Cloneable{
    public String name;
    public int age;
    Money money = new Money();

    public Person2() {
    }

    public Person2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Money getMoney() {
        return money;
    }

    public void setMoney(Money money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return "Person2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", money=" + money.money +
                '}';
    }

//    public Object clone() throws CloneNotSupportedException{//浅拷贝
//        return super.clone();
//    }

    public Object clone() throws CloneNotSupportedException{//深拷贝
        Person2 temp = (Person2) super.clone();
        temp.money = (Money)this.money.clone();
        return temp;
    }
}
